package cn.wolfcode.trip.base.service.impl;

import cn.wolfcode.trip.base.domain.Goods;
import cn.wolfcode.trip.base.domain.GoodsType;
import cn.wolfcode.trip.base.domain.User;
import cn.wolfcode.trip.base.mapper.GoodsMapper;
import cn.wolfcode.trip.base.mapper.GoodsTypeMapper;
import cn.wolfcode.trip.base.mapper.UserMapper;
import cn.wolfcode.trip.base.query.GoodsTypeQueryObject;
import cn.wolfcode.trip.base.query.QueryObject;
import cn.wolfcode.trip.base.service.IGoodsService;
import cn.wolfcode.trip.base.service.IUserService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class GoodsServiceImpl implements IGoodsService {

    @Autowired
    private GoodsMapper goodsMapper;

    @Autowired
    private GoodsTypeMapper goodsTypeMapper;

    public Goods selectGoods(Long id) {
        return null;
    }

    public void saveOrUpdate(Goods goods) {
        if (goods.getId() == null){
            goods.setReleaseTime(new Date());
            goodsMapper.insert(goods);
        }else {
            goodsMapper.updateByPrimaryKey(goods);
        }
    }

    public PageInfo<Goods> selectForList(QueryObject qo) {
        PageHelper.startPage(qo.getCurrentPage(),qo.getPageSize());
        List<Goods> list = goodsMapper.selectForList(qo);
        return new PageInfo<>(list);
    }

    public void delete(Long id) {
      goodsMapper.deleteByPrimaryKey(id);
    }


    public Goods getGoods(Long id) {
        return goodsMapper.selectByPrimaryKey(id);
    }


}
